package org.TCPcase3;

import java.io.*;
import java.net.Socket;

public class Client {
    public static void main(String[] args) throws IOException {
//        连接到服务器端口
        Socket socket=new Socket("127.0.0.1",10086);
//    先选择文件读取到字节数据，然后从用连接中获取的输出流来发送数据到服务端
        BufferedInputStream bis=new BufferedInputStream(new FileInputStream("C:\\Users\\夏明毅\\Desktop\\java课程代码\\mySocketnet\\clientDir\\xmy.text"));
        BufferedOutputStream outputStream=new BufferedOutputStream(socket.getOutputStream());
        int len=0;
        byte [] data=new byte[1024];
        System.out.println("开始读取文件数据");
        while ((len=bis.read(data))!=-1){
            outputStream.write(data,0,len);
            System.out.println(new String(data));
            outputStream.flush();

        }
//        发送结束标志,关闭输出流
        socket.shutdownOutput();
//        接收服务器的返回消息
        BufferedReader br=new BufferedReader(new InputStreamReader(socket.getInputStream()));
        String s = br.readLine();
        System.out.println(s);
    }
}
